//
//  common.h
//  ampcontroller
//
//  Created by Developer on 20/01/2014.
//  Copyright (c) 2014 Maestun Abidjan. All rights reserved.
//

#ifndef __COMMON_H__
#define __COMMON_H__


#include "math.h"
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "Wire.h"
#include "LiquidCrystal.h"



// ==============================================================================
#pragma mark - SETUP AMP BELOW
// ==============================================================================
#define ORANGE_OR15
#define MAX_INPUT_POTS  (5)
#define VERSION_MAJOR   (1)
#define VERSION_MINOR   (0)

// ==============================================================================
#pragma mark - AMPLIFIER HARDWARE DESCRIPTORS
// ==============================================================================
#define MEGA                    (unsigned long)(1000000)
#define KILO                    (unsigned long)(1000)
#define MAX_PATCHES             (16)
#define MAX_OUTPUT_STEPS        (256)
#define MAX_INPUT_STEPS         (1024)
#define MAX_NAME_LEN            (12)
#define DEBOUNCE_FILTER_DELAY   (100)


typedef unsigned char uint8_t;
#define D0                      (0)
#define D1                      (1)
#define D2                      (2)
#define D3                      (3)
#define D4                      (4)
#define D5                      (5)
#define D6                      (6)
#define D7                      (7)
#define D8                      (8)
#define D9                      (9)
#define D10                     (10)
#define D11                     (11)
#define D12                     (12)
#define D13                     (13)

typedef enum EPotType {
    EPotLog,
    EPotLin,
    EPotRLog
} EPotType;


// ==============================================================================
#pragma mark - DATA STRUCTURES
// ==============================================================================
typedef struct SPotDescriptor {
    const char *    name;
    bool            dual;
    EPotType        type;
    unsigned int    currentstep;
    unsigned long   inputvalue;
    unsigned long   outputvalue;
    unsigned char   inputaddress;
    unsigned char   outputaddress;
} SPotDescriptor;


typedef enum {
    EStateIdle = 0,
    EStateFade,
    EStateEdit
} EState;

typedef enum {
    EBluetoothCommandApplyPatch = 1,
    EBluetoothCommandSetPotValue,
    EBluetoothCommandToggleLoop,
    EBluetoothCommandSavePatch,
    EBluetoothCommandResetBank
} EBluetoothCommand;



extern const char * INPUT_NAMES[MAX_INPUT_POTS];
extern const bool INPUT_IS_DUAL[MAX_INPUT_POTS];
extern const EPotType INPUT_TYPE[MAX_INPUT_POTS];
extern const unsigned long INPUT_OHM[MAX_INPUT_POTS];
extern const unsigned long OUTPUT_OHM[MAX_INPUT_POTS];
extern const unsigned char INPUT_ADDRESS[MAX_INPUT_POTS];
extern const unsigned char OUTPUT_ADDRESS[MAX_INPUT_POTS];

extern SPotDescriptor   gPots[MAX_INPUT_POTS];

void init_pot_data();

#endif
